package com.hongdee.insurance.order.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.insurance.order.service.TInsuranceCommissionExamService;
import com.hongdee.insurance.quotation.service.ITInsuranceQuotationService;
import com.hongdee.insurance.quotationitem.service.ITInsuranceQuotationItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 王帅
 * @className TinsuranceCommissionExamController
 * @type class
 * @description 保险佣金审核Controller
 * @path com.hongdee.insurance.order.controller
 * @create 2017/6/12 10:13
 **/
@Controller
@RequestMapping("/insurance/commission/exam")
public class TinsuranceCommissionExamController {

    @Autowired
    private TInsuranceCommissionExamService insuranceCommissionExamService;
    @Autowired
    private ITInsuranceQuotationService quotationService;

    /**
     * 保险佣金审核查询
     * @param uid
     * @param token
     * @param data
     * @return
     */
    @RequestMapping("/page")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "10") String limit,
                    @RequestBody Map data) throws Exception {
        Map map=insuranceCommissionExamService.page(data,uid,start,limit);
        map.put("success",true);
        map.put("msg","查询成功！！");
        return map;
    }

    /**
     * 删除保单
     * @param uid
     * @param token
     * @param qId
     * @return
     * @throws Exception
     */
    @RequestMapping("/del")
    @ResponseBody
    public Map del(@RequestParam(name = "uid", defaultValue = "") String uid,
                   @RequestParam(name = "token", defaultValue = "") String token,
                   @RequestParam(name = "qId", defaultValue = "") String qId) throws Exception {
        quotationService.delInsuranceById(qId,true);
        Map map=new HashMap(2);
        map.put("success",true);
        map.put("msg","删除成功!!");
        return map;
    }

    /**
     * 佣金审核确认
     * @param uid
     * @param token
     * @param data
     * @return
     */
    @RequestMapping("/confim")
    @ResponseBody
    public ResultEntity confim(@RequestParam(name = "uid", defaultValue = "") String uid,
                               @RequestParam(name = "token", defaultValue = "") String token,
                               @RequestParam(name = "type", defaultValue = "") String type,
                               @RequestParam(name = "remark",defaultValue = "")String remark,
                               @RequestBody List<Map> data) throws Exception {
        ResultEntity res=new ResultEntity();
        this.insuranceCommissionExamService.examInsuranceCommission(uid,type,data,remark);
//        this.insuranceCommissionExamService.examInsurancePrice(uid,type,data);
        res.setSuccess(true);
        res.setMsg("佣金审核成功！！");
        return res;
    }

    /**
     * 保费审核
     * @param uid
     * @param token
     * @param type
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/confimPrice")
    @ResponseBody
    public ResultEntity confimPrice(@RequestParam(name = "uid", defaultValue = "") String uid,
                                    @RequestParam(name = "token", defaultValue = "") String token,
                                    @RequestParam(name = "type", defaultValue = "") String type,
                                    @RequestParam(name = "remark",defaultValue = "")String remark,
                                    @RequestBody List<Map> data) throws Exception {
        ResultEntity res=new ResultEntity();
//        this.insuranceCommissionExamService.examInsurancePrice(uid,type,data);
        this.insuranceCommissionExamService.examInsuranceCommission(uid,type,data,remark);
        res.setSuccess(true);
        res.setMsg("保费审核成功！！");
        return res;
    }

    /**
     * 保单佣金审核日志
     * @param uid
     * @param token
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/confim/list")
    @ResponseBody
    public ResultEntity confimList(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestParam(name = "id",defaultValue = "")String id) throws Exception {
        if("".equals(id)){
            throw new Exception("请选择保单信息!!");
        }
        ResultEntity res=new ResultEntity();
        List<Map<String,Object>> lists=this.insuranceCommissionExamService.findExalLogs(id);
        res.setSuccess(true);
        res.setData(lists);
        res.setMsg("查询成功!!");
        return res;
    }

}
